
source('utils.R')
source('read_dataset.R')

## inflation adjustment
cols = c('r_val','d_val','r_val_pcc_only','d_val_pcc_only')
df12[, (cols) := lapply(.SD, \(x) x * 1.12), .SDcols = cols]
df16[, (cols) := lapply(.SD, \(x) x * 1.037037), .SDcols = cols]

oc = df12[, .(tot = sum(d_val, na.rm = T)), .(clinton_donor = component %chin% df16[d_val > 0]$component, nat_quant)]
oc = oc[, tot[(clinton_donor)] / sum(tot), nat_quant]
oc[, class := 'Obama to Clinton']
oc[, cycle := '2012 to 2016']

rt16 = df12[, .(tot = sum(r_val, na.rm = T)), .(trump16_donor = component %chin% df16[r_val > 0]$component, nat_quant)]
rt16 = rt16[, tot[(trump16_donor)] / sum(tot), nat_quant]
rt16[, class := 'Romney to Trump \'16']
rt16[, cycle := '2012 to 2016']

ob = df12[, .(tot = sum(d_val, na.rm = T)), .(biden_donor = component %chin% df20[d_val > 0]$component, nat_quant)]
ob = ob[, tot[(biden_donor)] / sum(tot), nat_quant]
ob[, class := 'Obama to Biden']
ob[, cycle := '2012 to 2020']

rt20 = df12[, .(tot = sum(r_val, na.rm = T)), .(trump20_donor = component %chin% df20[r_val > 0]$component, nat_quant)]
rt20 = rt20[, tot[(trump20_donor)] / sum(tot), nat_quant]
rt20[, class := 'Romney to Trump\'20']
rt20[, cycle := '2012 to 2020']

save(oc, rt16, ob, rt20, file = 'summary_data/figA11.rda')
